package com.huatai.user.service.impl;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.huatai.common.error.exception.ServiceException;
import com.huatai.common.util.AuthUtil;
import com.huatai.common.util.ObjectUtil;
import com.huatai.user.entity.User;
import com.huatai.user.entity.UserCheckRecord;
import com.huatai.user.mapper.UserCheckRecordMapper;
import com.huatai.user.service.UserCheckRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 用户审核记录 服务实现类
 * </p>
 *
 * @author songxiude
 * @since 2024-05-29
 */
@Service
public class UserCheckRecordServiceImpl extends ServiceImpl<UserCheckRecordMapper, UserCheckRecord> implements UserCheckRecordService {

	@Autowired
	private UserService userService;
	/**
	 * 客户端用户审核
	 * @param userCheckRecord
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public boolean checkUser(UserCheckRecord userCheckRecord) {
		//保存用户审核状态
		User user = userService.getById(userCheckRecord.getUserId());
		if(ObjectUtil.isEmpty(user)){
			throw new ServiceException("用户不存在");
		}
		user.setCheckState(userCheckRecord.getCheckState());
		userService.updateById(user);
		userCheckRecord.setCheckUserId(AuthUtil.getUser().getUserId());
		return save(userCheckRecord);
	}
}
